from django.contrib import auth
from django.shortcuts import render,HttpResponse

# Create your views here.
from book.models import Book

def index(request):
	# 保存数据方式一
	# book_obj = Book(id=1,title = "金瓶梅",price = 100 ,pub_date = "2021-02-02",publish="人民教育出版色")
	# book_obj.save()
	# 方式二  create创建 返回创建后的对象
	# book_obj = Book.objects.create(title = "霍乱时期的爱情",price = 100 ,pub_date = "2021-02-02",publish="人民教育出版色")

	# 查询方法
	book_list = Book.objects.all()
	print(book_list)

	book_1 = Book.objects.all().first()
	book_2 = Book.objects.all()[2]
	book_3 = Book.objects.filter(title = "金瓶梅")
	book_4 = Book.objects.get(title = "霍乱时期的爱情")
	print(book_1)
	print(book_2)
	print(book_3)
	print(book_4)
	return render(request,"register.html")

def book_register(request):
	print(request)
	if request.is_ajax():
		print(type(request.POST))
		print(request.POST)
		# {'first_name': ['张'], 'second_name': ['坤'], 'pwd': ['123123'], 're_pwd': ['123123'], 'email': ['kijlee@163.com']}

		print(request.POST["first_name"][0])
		# user = auth.authenticate(username='user', password='password')
		auth.re
	return render(request,"book_register.html")
